from django.shortcuts import render

# Create your views here.
from django.contrib.auth.models import User, Group
from rest_framework import serializers
from app01.serializers import BookSerializer, AutherSerializer
from rest_framework.viewsets import ModelViewSet
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework_bulk import ListCreateBulkUpdateDestroyAPIView, BulkModelViewSet
from app01.models import Books, Auther
from rest_framework.filters import SearchFilter
from .utils import MyFilter

class BooksViewSet(BulkModelViewSet):
    queryset = Books.objects.all()
    serializer_class = BookSerializer
    filter_backends = [MyFilter]
    filter_fields = ["id"]
    
    def allow_bulk_destroy(self, qs, filtered):
        return qs is not filtered
        

class AutherViewSet(BulkModelViewSet):
    queryset = Auther.objects.all()
    serializer_class = AutherSerializer